﻿using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;
using System.Linq;
namespace HelperPrototype.Reports {
    
    
    public partial class DS_PhieuDeNghiTamUng {
        partial class PhieuDeNghiTamUngDataTable
        {
        }
        private string Ma = "";
        public void fillData(string ID)
        {

            this.Ma = ID;
            SqlConnection con = new SqlConnection(Properties.Settings.Default.myConnectionString);
            con.Open();

            string sql = "SELECT PTU.MaPhieu, PTU.MaNguoiTao, PTU.NgayTao, PTU.MaNguoiDuyet, PTU.NgayDuyet, PTU.LyDoKhongDuyet, PTU.SoTien, PTU.ThoiGian, PTU.NoiDung, PTU.deleted, N1.Ten AS NguoiTao, N2.Ten AS NguoiDuyet, QT.MaPhieuDeNghiMuaHang" +
            " FROM dbo.PhieuTamUng PTU, dbo.NguoiDung N1, dbo.NguoiDung N2, dbo.QuyTrinhMuaHang QT" +
            " WHERE (PTU.MaPhieu = '" + ID + "') AND (QT.MaPhieuTamUng = '" + ID + "') AND N1.MaNguoiDung = PTU.MaNguoiTao AND N2.MaNguoiDung = PTU.MaNguoiDuyet";
            SqlDataAdapter dataAdaptor = new SqlDataAdapter(sql, con);
            dataAdaptor.Fill(this, "PhieuDeNghiTamUng");

            //DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable tb = new DS_PhieuMuaHang.PhieuDeNghiMuaHangDataTable();
            //DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter da = new DS_PhieuMuaHangTableAdapters.PhieuDeNghiMuaHangTableAdapter();

            //da.Fill(tb, ID);

        }

        public void viewReport()
        {

            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            _DB.PhieuTamUng P = dc.PhieuTamUngs.Single(s => s.MaPhieu == Ma);

            



            trash.CR_PhieuDeNghiTamUng report = new trash.CR_PhieuDeNghiTamUng();
            report.SetDataSource(this);
            report.SetParameterValue("MaPhieu", P.MaPhieu);
            ReportViewerForm form = new ReportViewerForm(report);
            form.ShowDialog();
        }
    }
}

namespace HelperPrototype.DS_PhieuDeNghiTamUngTableAdapters {


    public partial class PhieuDeNghiTamUngTableAdapter
    {
    }
}
